<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"/>
    <title>nextTick的使用</title>
    <link rel="stylesheet" href="css/swiper.css">
    <style>
        [v-cloak] {
            display: none;
        }

        .swiper-container {
            width: 600px;
            height: 350px;
        }

        .swiper-container img {
            width: 100%;
            height: 100%
        }
    </style>
</head>
<body>
<div id="app" v-cloak></div>
<script src="js/vue.js"></script>
<script src="js/swiper.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
    let App = {
        template: `
        <div>
            <div class="swiper-container" ref="swiper-container">
              <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="(item,index) in swipers" :key="index"><img :src="item.image" alt=""></div>
              </div>
              <div class="swiper-pagination" ref="swiper-pagination"></div>
            </div>
        </div>
      `,
        data() {
            return {
                swipers: []
            }
        },
        //初始化之前
        beforeCreate() {
            console.log("beforeCreate");
        },
        //初始化完成（不能获取dom，一般用于获取ajax数据）
        created() {
            console.log("created");
            var $this = this;
            $.get("http://vueshop.glbuys.com/api/home/index/slide?token=1ec949a15fb709370f", function (res) {
                var jsonRes = JSON.parse(res);
                if (jsonRes.code == 200) {
                    $this.swipers = jsonRes.data;
                    $this.$nextTick(function () {
                        new Swiper($this.$refs['swiper-container'], {
                            autoplay: 3000,
                            pagination: $this.$refs['swiper-pagination'],
                            paginationClickable: true,
                            autoplayDisableOnInteraction: false
                        })
                    });
                    // setTimeout(()=>{
                    //     new Swiper($this.$refs['swiper-container'], {
                    //         autoplay: 3000,
                    //         pagination : $this.$refs['swiper-pagination'],
                    //         paginationClickable :true,
                    //         autoplayDisableOnInteraction : false
                    //     })
                    // },100)
                }
            })
        },
        //挂载之前
        beforeMount() {
            console.log("beforeMount");
        },
        //挂载完成之后（可以获取dom）
        mounted() {

        },
        //数据更新之前
        beforeUpdate() {
            console.log("beforeUpdate");
        },
        //数据更新之后
        updated() {
            console.log("updated");
        }

    };
    new Vue({
        el: "#app",
        template: `
            <App></App>
        `,
        components: {
            App
        }
    })
</script>
</body>
</html>
